//引入路由插件
import VueRouter from "vue-router";
import login from "@/components/login";
import login_temporary from "@/components/login_temporary";
import login_register from "@/components/login_register";
import login_user from "@/components/login_user";
import user from "@/components/user";
import user_parking from "@/components/user_parking";
import user_order from "@/components/user_order";
import index from "@/components/index";
import user_proposal from "@/components/user_proposal";
import superUser from "@/components/superUser";
import superUser_parking from "@/components/superUser_parking";
import superUser_add from "@/components/superUser_addParking";
import superUser_order from "@/components/superUser_order";
import superUser_updateOrder from "@/components/superUser_updateOrder";
import superUser_proposal from "@/components/superUser_proposal";
import SuperIndex from "@/components/SuperIndex";
import pay from "@/components/pay";
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

//创建并暴露路由器
export default new VueRouter({
    routes: [
        {
            path: "/login",
            component: login,
            props: true,
            children: [
                {
                    path: "login_temporary",
                    component: login_temporary,
                },
                {
                    path: "login_register",
                    component: login_register,
                },
                {
                    path: "login_user",
                    component: login_user,
                }
            ]
        },
        {
            name: 'user',
            path: "/user",
            component: user,
            props($route) {
                return {
                    email: $route.query.email,
                }
            },
            children: [
                {
                    name: 'user_parking',
                    path: "user_parking",
                    component: user_parking,
                    //props的第三种写法，值为函数
                    props($route) {
                        return {
                            parking: $route.query.parking,
                            email: $route.query.email,
                        }
                    }
                },
                {
                    name: 'user_order',
                    path: "/user_order",
                    component: user_order,
                    props($route) {
                        return {
                            order: $route.query.order,
                            email: $route.query.email,
                        }
                    }
                },
                {
                    name: 'pay',
                    path: "pay",
                    component: pay,
                    props($route) {
                        return {
                            pay: $route.query.pay,
                            id: $route.query.id,
                            email: $route.query.email,
                            price: $route.query.price,
                        }
                    }
                },
                {
                    name: 'index',
                    path: "/index",
                    component: index,
                    props($route) {
                        return {
                            email: $route.query.email,
                        }
                    }
                },
                {
                    name: 'user_proposal',
                    path: "/user_proposal",
                    component: user_proposal,
                    props($route) {
                        return {
                            email: $route.query.email,
                            proposal: $route.query.proposal,
                        }
                    }
                }
            ]
        },
        {
            name: 'superUser',
            path: "/superUser",
            component: superUser,
            children: [
                {
                    name: 'superUser_parking',
                    path: "superUser_parking",
                    component: superUser_parking,
                    props($route) {
                        return {
                            parking: $route.query.parking,
                            email: $route.query.email,
                        }
                    },
                },
                {
                    name: 'superUser_order',
                    path: "superUser_order",
                    component: superUser_order,
                    props($route) {
                        return {
                            order: $route.query.order,
                        }
                    }
                },
                {
                    name: 'superUser_proposal',
                    path: "superUser_proposal",
                    component: superUser_proposal,
                    props($route) {
                        return {
                            proposal: $route.query.proposal,
                        }
                    }
                },
                {
                    name: 'SuperIndex',
                    path: "SuperIndex",
                    component: SuperIndex,
                },
                {
                    name: 'superUser_add',
                    path: "superUser_add",
                    component: superUser_add,
                    props($route) {
                        return {
                            id: $route.query.id,
                            address: $route.query.address,
                            parkingSpaceNumber: $route.query.parkingSpaceNumber,
                            price: $route.query.price,
                            state: $route.query.state,
                            email: $route.query.email,
                        }
                    },
                },
                {
                    name: 'superUser_updateOrder',
                    path: "superUser_updateOrder",
                    component: superUser_updateOrder,
                    props($route) {
                        return {
                            id: $route.query.id,
                            name: $route.query.name,
                            parkingSpaceNumber: $route.query.parkingSpaceNumber,
                            licensePlateNumber: $route.query.licensePlateNumber,
                            orderPrice: $route.query.orderPrice,
                            orderState: $route.query.orderState,
                        }
                    },
                }

            ]
        },
    ]
})